<template>
    <Input :value="cValue" @on-blur='change' placeholder="请填写数值"></Input>
</template>
<script>
    export default{
        name: 'CNumberInput',
        props: {
            value: String,
            type: {
                type:String,
                default:'number'//number price
            },
            zero: {
                type:String,
                default:'number'//number price
            },
        },
        computed:{
            cValue(){
                return this.dataTrim(this.value)
            }
        },
        data(){
            return{
                
            }
        },
        mounted(){

        },
        methods:{
            dataTrim(v){
                if(!v){
                    return this.type=='price'?'0.00':'0';
                }else {
                    v  =  parseFloat(v);
                    if(typeof v == 'number'&&!isNaN(v)){
                        /*if(v<=0){
                            v = 0;
                        }*/
                        return this.type=='price'?v.toFixed(2):v.toFixed(0);
                    }else {
                        return this.type=='price'?'0.00':'0';
                    }
                }
            },
            change($event){
                this.$emit('input', $event.target.value);
                this.$nextTick(()=>{
                    this.$emit('input', this.dataTrim($event.target.value))
                })
            }
        },
        components:{
        },
        watch:{
            value(){
                this.$emit('input', this.cValue);
            }
        }
    }
</script>